package com.lemon.stock.compose

import androidx.compose.foundation.layout.padding
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import androidx.paging.ExperimentalPagingApi
import com.lemon.stock.R
import com.lemon.stock.local.NavigationTab
import com.lemon.stock.viewmodel.MainViewModel

//@Preview
@ExperimentalPagingApi
@Composable
fun MainScreen(navController: NavHostController) {
    val vm: MainViewModel = viewModel()
    val position by vm.position.observeAsState()
    val tabs = NavigationTab.values()

    Scaffold(
        //backgroundColor = colorResource(id = R.color.white),
        //contentColor = Color.Red,
        bottomBar = {
            BottomNavigation(
                //Modifier.navigationBarsHeight(additional = 56.dp)
            ){
                tabs.forEach { tab->
                    BottomNavigationItem(
                        icon = {Icon(painterResource(tab.icon), contentDescription = null)},
                        label = {Text(stringResource(id = tab.title))},
                        selected = tab == position,
                        onClick = {
                            vm.onPositionChanged(tab)
                        })
                }
            }
        }
    ) {
        when(position){
            NavigationTab.Home-> HomeScreen()
            NavigationTab.Trade-> SurveyScreen()
            NavigationTab.Mine-> MineScreen(navController)
        }
    }

}

